﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading.Tasks;
using System.Net.Mail;
using ESupervision.Models;


namespace ESupervision.Services
{
    /// <summary>
    /// EmailNotificationService implements the INotificationService interface to support the email notification.
    /// Use System.Net.Mail.SmtpClient to send mail. The configuration is managed on web.config configuration file.
    /// </summary>
    public class EmailNotificationService : INotificationService
    {
        public async Task SendAllocatedNotificationToStudents(List<Student> students)
        {
            var body = "<div>Dear Students,<div><br></div><div><br></div><div>You are allocated to new supervisor and second marker on E-Supervision system. Please go to the E-Supervision website for more details.</div><div><br></div><div>Best regards,</div><div>E-Supervision system.</div></div>";
            var message = new MailMessage();
            foreach (var student in students)
            {
                message.To.Add(new MailAddress(student.Email));  // replace with valid value     
            }

            message.Subject = "Allocation notification from E-Supervision";
            message.Body = body;
            message.IsBodyHtml = true;
            using (var smtp = new SmtpClient())
            {

                await smtp.SendMailAsync(message);

            }
        }

        public async Task SendAllocatedNotificationToTeachers(List<Teacher> teachers)
        {
            var body = "<div>Dear Teachers,<div><br></div><div><br></div><div>You are allocated to new students on E-Supervision system. Please go to the E-Supervision website for more details.</div><div><br></div><div>Best regards,</div><div>E-Supervision system.</div></div>";
            var message = new MailMessage();
            foreach (var teacher in teachers)
            {
                message.To.Add(new MailAddress(teacher.Email));  // replace with valid value     
            }

            message.Subject = "Allocation notification from E-Supervision";
            message.Body = body;
            message.IsBodyHtml = true;
            using (var smtp = new SmtpClient())
            {

                await smtp.SendMailAsync(message);

            }
        }

        public async Task SendDeallocatedNotificationToTeachers(List<Teacher> teachers)
        {
            var body = "<div>Dear Teachers,<div><br></div><div><br></div><div>You are deallocated for some students on E-Supervision system. Please go to the E-Supervision website for more details.</div><div><br></div><div>Best regards,</div><div>E-Supervision system.</div></div>";
            var message = new MailMessage();
            foreach (var teacher in teachers)
            {
                message.To.Add(new MailAddress(teacher.Email));  // replace with valid value     
            }

            message.Subject = "Deallocation notification from E-Supervision";
            message.Body = body;
            message.IsBodyHtml = true;
            using (var smtp = new SmtpClient())
            {

                await smtp.SendMailAsync(message);

            }
        }
    }
}